package com.team.recruitment_management_system.controller;


import com.team.recruitment_management_system.service.FileService;
import com.team.recruitment_management_system.util.result.Result;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RequestMapping("/file")
@RestController
@Tag(name = "文件上传")
public class FileController {
    @Autowired
    FileService fileUploadService;

    //使用默认路径
    @PostMapping("/upload")
    @Operation(summary = "使用默认路径上传", security = {@SecurityRequirement(name = "Authorization")})
    public Result upload(MultipartFile file) throws Exception {
        fileUploadService.upload(file, null);

        return Result.ok(null, "上传成功，下载文件请输入文件名称不要后缀即可");
    }

    //自定义路径
    @PostMapping("/upload/template")
    @Operation(summary = "使用自定义路径上传，请使用默认路径上传", security = {@SecurityRequirement(name = "Authorization")})
    public String uploadPlace(MultipartFile file) throws Exception {
        fileUploadService.upload(file, "F:\\upload");

        return null;
    }

    //下载
    @GetMapping("/download/file/{name}")
    @Operation(summary = "文件下载")
    public String downloadFile(HttpServletResponse response, @PathVariable String name) throws IOException {
        boolean y = fileUploadService.download(response, name);

        return null;
    }
}

